﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Cd.NET;
using System.Diagnostics;

namespace ACTKTest
{
    public partial class Form1 : Form
    {

        Canvas c;

        public Form1()
        {
            InitializeComponent();

            c = new Canvas(Context.NativeWindow, Handle);

            SetFrogStipple(c);
        }

        private void DecodeColor(int col, out byte r, out byte g, out byte b)
        {
            r = (byte)((col >> 16) & 255);
            g = (byte)((col >> 8) & 255);
            b = (byte)(col & 255);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            IntPtr canvas = Cdc.CreateCanvasPtr(Cdc.ContextNativeWindow(), Handle);

            Cdc.CanvasForeground(canvas, 0xffffff);

            Cdc.CanvasTextAlignment(canvas, (int)TextAlignment.Center);

            Cdc.CanvasText(canvas, 200, 200, "Första raden är en lång rad");
            Cdc.CanvasMark(canvas, 200, 200);

            Cdc.KillCanvas(canvas);
        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {

            //c.Activate();
            /*c.Foreground = 0xff0000;
            c.Background = 0;

            int bk = c.Background;
            */
            c.Clear();

            


            c.SetFont("Times", FontStyle.Plain, 14);

            c.TextOrientation = 45.0;

            c.TextAlignment = TextAlignment.Center;

            c.Text(200, 200, "Första raden är en lång rad");


            int mw, a, d, h;
            c.GetFontDim(out mw, out h, out a, out d);


            double dmw, da, dd, dh;
            c.WorldGetFontDim(out dmw, out dh, out da, out dd);

            

            c.Line(0, 0, 200, 200);
        
          

           // c.Box(0, 160,0,180);
        }

        void SetFrogStipple(Canvas can)
        {
            System.Drawing.Bitmap b = System.Drawing.Bitmap.FromFile("c:\\temp\\frog.jpg") as System.Drawing.Bitmap;
            List<int> i = new List<int>();
            for (int y = 0; y < b.Width; y++)
            {
                for (int x = 0; x < b.Width; x++)
                {
                    System.Drawing.Color c = b.GetPixel(x, y);
                    int col = Cdc.EncodeColor(c.R, c.G, c.B);
                    i.Add(col);
                }
            }

            can.WorldSetPattern(b.Width, b.Height, i.ToArray(),20,20);



            

        }
    }
}
